<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: SemesterController</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">SemesterController</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/app/controllers/semester_controller_rb.html">
                app/controllers/semester_controller.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="ApplicationController.html">
                ApplicationController
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000009">generate_next</a>&nbsp;&nbsp;
      <a href="#M000010">generate_prev</a>&nbsp;&nbsp;
      <a href="#M000011">select_solution</a>&nbsp;&nbsp;
      <a href="#M000007">show</a>&nbsp;&nbsp;
      <a href="#M000012">show_previews</a>&nbsp;&nbsp;
      <a href="#M000008">toggle_section</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">NPREVIEWS</td>
          <td>=</td>
          <td class="context-item-value">6</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000009" class="method-detail">
        <a name="M000009"></a>

        <div class="method-heading">
          <a href="#M000009" class="method-signature">
          <span class="method-name">generate_next</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
display the next generated schedules
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000009-source">
<pre>
     <span class="ruby-comment cmt"># File app/controllers/semester_controller.rb, line 152</span>
152:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">generate_next</span>
153:     <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:solution</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">generate</span>
154: 
155:     <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:marker</span>] <span class="ruby-operator">+=</span> <span class="ruby-constant">NPREVIEWS</span>
156: 
157:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:marker</span>] <span class="ruby-operator">&gt;=</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:solution</span>].<span class="ruby-identifier">length</span>
158:       <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:marker</span>] = <span class="ruby-value">0</span>
159:     <span class="ruby-keyword kw">end</span>
160: 
161:     <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:solution</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">load_sections</span>
162:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000010" class="method-detail">
        <a name="M000010"></a>

        <div class="method-heading">
          <a href="#M000010" class="method-signature">
          <span class="method-name">generate_prev</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
display the previous generated schedules
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000010-source">
<pre>
     <span class="ruby-comment cmt"># File app/controllers/semester_controller.rb, line 165</span>
165:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">generate_prev</span>
166:     <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:solution</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">generate</span>
167:    
168:     <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:marker</span>] <span class="ruby-operator">-=</span> <span class="ruby-constant">NPREVIEWS</span>
169: 
170:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:marker</span>] <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
171:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:solution</span>].<span class="ruby-identifier">length</span>.<span class="ruby-identifier">remainder</span>(<span class="ruby-constant">NPREVIEWS</span>) <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
172:         <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:marker</span>] = <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:solution</span>].<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-constant">NPREVIEWS</span>
173:       <span class="ruby-keyword kw">else</span>
174:         <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:marker</span>] = <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:solution</span>].<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:solution</span>].<span class="ruby-identifier">length</span>.<span class="ruby-identifier">remainder</span>(<span class="ruby-constant">NPREVIEWS</span>)
175:       <span class="ruby-keyword kw">end</span>
176:     <span class="ruby-keyword kw">end</span>
177: 
178:     <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:solution</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">load_sections</span>
179:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000011" class="method-detail">
        <a name="M000011"></a>

        <div class="method-heading">
          <a href="#M000011" class="method-signature">
          <span class="method-name">select_solution</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
select a schedule from the previews window
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000011-source">
<pre>
     <span class="ruby-comment cmt"># File app/controllers/semester_controller.rb, line 182</span>
182:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">select_solution</span>
183:     <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:solution</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">load_sections</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:chosen</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:chosen</span>].<span class="ruby-identifier">to_i</span>)
184:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000007" class="method-detail">
        <a name="M000007"></a>

        <div class="method-heading">
          <a href="#M000007" class="method-signature">
          <span class="method-name">show</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
<a href="SemesterController.html#M000007">show</a> semester schedule
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000007-source">
<pre>
     <span class="ruby-comment cmt"># File app/controllers/semester_controller.rb, line 101</span>
101:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">show</span>
102:     <span class="ruby-ivar">@semester</span> = <span class="ruby-constant">Semester</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>])
103: 
104:     <span class="ruby-ivar">@start_time</span> = <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>,<span class="ruby-value">1</span>,<span class="ruby-value">1</span>,<span class="ruby-value">8</span>)
105:     <span class="ruby-ivar">@end_time</span> = <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>,<span class="ruby-value">1</span>,<span class="ruby-value">1</span>,<span class="ruby-value">21</span>,<span class="ruby-value">30</span>)
106:     <span class="ruby-ivar">@time_inc</span> = <span class="ruby-value">15</span><span class="ruby-operator">/</span>(<span class="ruby-value">24.0</span><span class="ruby-operator">*</span><span class="ruby-value">60</span>) <span class="ruby-comment cmt">#15.0/(24.0*60.0)</span>
107: 
108:     <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:solution</span>] = <span class="ruby-keyword kw">nil</span>
109:     <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:marker</span>] = <span class="ruby-keyword kw">nil</span>
110:     <span class="ruby-comment cmt">#        time.strftime(&quot;%H:%M&quot;)</span>
111:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000012" class="method-detail">
        <a name="M000012"></a>

        <div class="method-heading">
          <a href="#M000012" class="method-signature">
          <span class="method-name">show_previews</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
generate schedules and <a href="SemesterController.html#M000007">show</a>
the previews window
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000012-source">
<pre>
     <span class="ruby-comment cmt"># File app/controllers/semester_controller.rb, line 187</span>
187:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">show_previews</span>
188:     <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:solution</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">generate</span>
189:     <span class="ruby-identifier">load_sections</span>(<span class="ruby-keyword kw">nil</span>, <span class="ruby-keyword kw">true</span>)
190:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000008" class="method-detail">
        <a name="M000008"></a>

        <div class="method-heading">
          <a href="#M000008" class="method-signature">
          <span class="method-name">toggle_section</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
add/remove section from semester schedule
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000008-source">
<pre>
     <span class="ruby-comment cmt"># File app/controllers/semester_controller.rb, line 114</span>
114:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">toggle_section</span>
115: 
116:     <span class="ruby-comment cmt"># friend is viewing schedule</span>
117:     <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Semester</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>]).<span class="ruby-identifier">user</span>.<span class="ruby-identifier">id</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:user</span>]
118:       <span class="ruby-keyword kw">return</span>
119:     <span class="ruby-keyword kw">end</span>
120: 
121:     <span class="ruby-identifier">user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:user</span>]
122:     <span class="ruby-identifier">section</span> = <span class="ruby-constant">CisSection</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:section</span>])
123:     <span class="ruby-identifier">plan</span> = <span class="ruby-identifier">user</span>.<span class="ruby-identifier">semesters</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>]).<span class="ruby-identifier">course_plan</span>
124: 
125:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">plan</span>.<span class="ruby-identifier">cis_sections</span>.<span class="ruby-identifier">exists?</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:section</span>]
126:       <span class="ruby-identifier">plan</span>.<span class="ruby-identifier">cis_sections</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">section</span>
127:     <span class="ruby-keyword kw">else</span>
128:       <span class="ruby-identifier">plan</span>.<span class="ruby-identifier">cis_sections</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">section</span>
129:     <span class="ruby-keyword kw">end</span>
130: 
131:     <span class="ruby-ivar">@semester</span> = <span class="ruby-constant">Semester</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:id</span>])
132: 
133:     <span class="ruby-comment cmt"># TODO clean this up</span>
134:     <span class="ruby-ivar">@start_time</span> = <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>,<span class="ruby-value">1</span>,<span class="ruby-value">1</span>,<span class="ruby-value">8</span>)
135:     <span class="ruby-ivar">@end_time</span> = <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>,<span class="ruby-value">1</span>,<span class="ruby-value">1</span>,<span class="ruby-value">21</span>,<span class="ruby-value">30</span>)
136:     <span class="ruby-ivar">@time_inc</span> = <span class="ruby-value">15</span><span class="ruby-operator">/</span>(<span class="ruby-value">24.0</span><span class="ruby-operator">*</span><span class="ruby-value">60</span>)
137:     <span class="ruby-ivar">@courses</span> = <span class="ruby-ivar">@semester</span>.<span class="ruby-identifier">cis_courses</span>
138:     <span class="ruby-ivar">@plan</span> = <span class="ruby-ivar">@semester</span>.<span class="ruby-identifier">course_plan</span>
139:     <span class="ruby-identifier">course</span> = <span class="ruby-identifier">section</span>.<span class="ruby-identifier">cis_semester</span>.<span class="ruby-identifier">cis_course</span>
140: 
141:     <span class="ruby-identifier">sections</span> = <span class="ruby-identifier">course</span>.<span class="ruby-identifier">sections_for_semester</span> <span class="ruby-ivar">@semester</span>
142: 
143:     <span class="ruby-identifier">render</span> <span class="ruby-identifier">:update</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">page</span><span class="ruby-operator">|</span>
144:       <span class="ruby-identifier">page</span>.<span class="ruby-identifier">replace_html</span> <span class="ruby-value str">'times_row'</span>, <span class="ruby-identifier">:partial</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'times_row'</span>, <span class="ruby-identifier">:locals</span> =<span class="ruby-operator">&gt;</span> {<span class="ruby-identifier">:semester</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@semester</span>}
145:       <span class="ruby-identifier">page</span>.<span class="ruby-identifier">replace_html</span> <span class="ruby-node">&quot;sects_#{@semester.id}_#{course.id}&quot;</span>, <span class="ruby-identifier">:partial</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'section_choice'</span>, <span class="ruby-identifier">:collection</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">sections</span>, <span class="ruby-identifier">:locals</span> =<span class="ruby-operator">&gt;</span> {<span class="ruby-identifier">:semester</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@semester</span>}
146:     <span class="ruby-keyword kw">end</span>
147:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>